// 所有的api接口做统一管理

import requests from './request'

import mockRequests from './mockajax'

// home模块
// axios请求结构是一个Promise对象
export const requeCategoryList = ()=>{
   return requests({url: "/product/getBaseCategoryList", method: 'get'})
}
export const reqGetBannerList = ()=>{
   return mockRequests.get('/banner')
}

export const reqGetFloorList = ()=>{
   return mockRequests.get('/floor')
}

// search模块 
// 商品搜索 必须要有一个参数，至少为一个空对象
export const reqGetSearchInfo = (params)=>{
   return requests.post('/list', {data: params})
}

// 获取商品详情
export const reqGetGoodsInfo = (skuId)=>{
   return requests.get(`/item/${skuId}`)
}

// 将产品添加到购物车中（获取更新某一个产品的个数）
export const reqAddOrUpdataeShopCart = (skuId, skuNum)=>{
   return requests.post(`/cart/addToCart/${skuId}/${skuNum}`)
}

// 获取购物车列表数据的接口
export const reqCartList = ()=>{
   return requests.get("/cart/cartList")
}

// 删除购物车产品的接口
export const reqdeleteCartById = (skuId)=>{
   return requests.delete(`/cart/deleteCart/${skuId}`)
}

// 切换商品选中状态
export const reqUpdateCheckedById = (skuId,isChecked)=>{ 
   return requests.get(`/cart/checkCart/${skuId}/${isChecked}`)
}

// 获取验证码
export const reqGetCode = (phone)=>{ 
   return requests.get(`/user/passport/sendCode/${phone}`)
}

// 用户注册
export const reqUserRegister = (data)=>{ 
   return requests.post("/user/passport/register", data)
}

// 用户登录
export const reqUserLogin = (data) =>{
   return requests.post("/user/passport/login", data)
}

// 获取用户信息【需要携带token获取用户信息】
export const reqGetUserInfo =()=>{
   return requests.get("/user/passport/auth/getUserInfo")
}
// 退出登录
export const reqLogout =()=>{
   return requests.get("/user/passport/logout")
}

// 获取用户地址信息
export const reqAddressInfo = ()=>{
   return requests.get("/user/userAddress/auth/findUserAddressList")
}

// 获取商品清单
export const reqOrderInfo = ()=>{
   return requests.get("/order/auth/trade")
}

// 提交订单
export const reqSubmitOrder = (tradeNo, data)=>{
   return requests.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`, data)
}

// 获取支付信息 /api
export const reqPayInfo = (orderId)=>{
   return requests.get(`/payment/weixin/createNative/${orderId}`)
}

// 查询支付订单的状态
export const reqPayStatus = (orderId) =>{
   return requests.get(`/payment/weixin/queryPayStatus/${orderId}`)
}

// 获取我的订单列表(个人中心)
export const reqMyOrderList = (page, limit)=>{
   return requests.get(`/order/auth/${page}/${limit}`)
}
